/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.business.repository;

import me.zhengjie.business.domain.KC21;
import me.zhengjie.business.domain.KC22;
import me.zhengjie.business.domain.vo.Kc21Vo;
import me.zhengjie.business.domain.vo.Kc22Vo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 照护保险登记信息
* @author xiahongbo
 * @date 2023-05-10
**/
public interface Kc22Repository extends JpaRepository<KC22, String>, JpaSpecificationExecutor<KC22> {

    @Query(value = "select new me.zhengjie.business.domain.vo.Kc22Vo( " +
            "r1.akb020, " +
            "r1.akc190, " +
            "r1.akc221, " +
            "r1.akc222, " +
            "r1.akc223, " +
            "r1.akc225, " +
            "r1.akc226, " +
            "r1.akc227, " +
            "r1.akc228, " +
            "r1.akc253, " +
            "r1.aae072, " +
            "r1.id, " +
            "r1.akc220, " +
            "r1.akc515) " +
            "from KC22 r1 " +
            " where  1=1 " +
            "   and (?1 IS NULL OR ?1 = '' OR r1.akc190 = ?1 ) " +
            "   and (?2 IS NULL OR ?2 = '' OR r1.akc221 = to_date(?2, 'yyyy-mm-dd') ) " +
            "   and (?3 IS NULL OR ?3 = '' OR r1.akc222 = ?3 ) " +
            "   and (?4 IS NULL OR ?4 = '' OR r1.akc223 = ?4 ) ",
            countQuery = "select count(*) from KC22 r1 " +
                    " where 1=1 " +
                    "   and (?1 IS NULL OR ?1 = '' OR r1.akc190 = ?1 ) " +
                    "   and (?2 IS NULL OR ?2 = '' OR r1.akc221 = to_date(?2, 'yyyy-mm-dd') ) " +
                    "   and (?3 IS NULL OR ?3 = '' OR r1.akc222 = ?3 ) " +
                    "   and (?4 IS NULL OR ?4 = '' OR r1.akc223 = ?4 ) ")
    Page<Kc22Vo> queryKc22VoPageList(String akc190, String akc221, String akc222 , String akc223, Pageable pageable);


    @Query(value = "select new me.zhengjie.business.domain.vo.Kc22Vo( " +
            "r1.akb020, " +
            "r1.akc190, " +
            "r1.akc221, " +
            "r1.akc222, " +
            "r1.akc223, " +
            "r1.akc225, " +
            "r1.akc226, " +
            "r1.akc227, " +
            "r1.akc228, " +
            "r1.akc253, " +
            "r1.aae072, " +
            "r1.id, " +
            "r1.akc220, " +
            "r1.akc515) " +
            "from KC22 r1 " +
            " where  1=1 " +
            "   and (?1 IS NULL OR ?1 = '' OR r1.akc190 = ?1 ) " +
            "   and (?2 IS NULL OR ?2 = '' OR r1.akc221 = to_date(?2, 'yyyy-mm-dd') ) " +
            "   and (?3 IS NULL OR ?3 = '' OR r1.akc222 = ?3 ) " +
            "   and (?4 IS NULL OR ?4 = '' OR r1.akc223 = ?4 ) ")
    List<Kc22Vo> queryKc22VoAllList(String akc190, String akc221, String akc222 , String akc223);

}